<template>
	<view>
		<view class="nav">
			<u-subsection :list="list" ref="tabs" @change="change" :current="current" mode="subsection"></u-subsection>
		</view>
		
		<view class="swiper-box" v-show="current==0">
			<view class="u-flex uni-center-content item" v-for="b in detail[0].list" :key="b.id">
				<view class="flex-left">
					<view class="title">{{b.text}}</view>
					<view class="time">{{b.addTime}}</view>
				</view>
				<view class="number">-{{b.number}}</view>
			</view>
			<u-loadmore :status="detail[0].loadingType" bgColor="#fafafa" marginTop="30"></u-loadmore>
		</view>
		<view class="swiper-box" v-show="current==1">
			<view class="u-flex uni-center-content item" v-for="b in detail[1].list" :key="b.id">
				<view class="flex-left">
					<view class="title">{{b.text}}</view>
					<view class="time">{{b.addTime}}</view>
				</view>
				<view class="number">+{{b.number}}</view>
			</view>
			<u-loadmore :status="detail[1].loadingType" bgColor="#fafafa" marginTop="30"></u-loadmore>
		</view>
		<view class="swiper-box cz-list" v-show="current==2">
			<view class="mark" v-if="detail[2].list.length>0">备注：长按失败记录可查看提现失败原因</view>
			<view class="u-flex item" v-for="t in detail[2].list" :key="t.id" @longtap="showNote(t)">
				<view class="number">￥{{t.number}}</view>
				<view class="status">{{t.text}}</view>
				<view class="time">{{t.addTime}}</view>
			</view>
			<u-loadmore :status="detail[2].loadingType" bgColor="#fafafa" marginTop="30"></u-loadmore>
		</view>
		<u-modal v-model="show" title="失败原因" :content="content"></u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show:false,
				content:"",
				list: [
					{
						name: '支出'
					}, 
					{
						name: '收入'
					}, 
					{
						name: '充值'
					}
				],
				detail:[
					{
						state: "3,5,9",
						loadingType: 'loadmore',
						list: [],
						page:1
					},
					{
						state: "1,2,4,6,7,8,10",
						loadingType: 'loadmore',
						list: [],
						page:1
					},
					{
						state: "-1",
						loadingType: 'loadmore',
						list: [],
						page:1
					}
				],
				limit:10,
				current: 0,
				dx: 0,
			};
		},
		onReachBottom() {
			this.loadMore();
		},
		onLoad(option) {
			if(option.type){
				this.current = option.type;
			}
			this.loadMore();
		},
		methods:{
			// tab栏切换
			change(e) {
				if(this.current != e){
					this.current = e;
					this.loadMore("tabChange");
				}
			},
			async loadMore(status) {
				//这里是将订单挂载到tab列表下
				let index = this.current;
				let navItem = this.detail[index];
				if(status === 'tabChange' && navItem.loaded === true){
					//tab切换只有第一次需要加载数据
					return;
				}
				if(navItem.loadingType === 'loading'||navItem.loadingType === 'nomore'){
					//防止重复加载
					return;
				}
				
				navItem.loadingType = 'loading';
				await this.$request.post("/balance/list", {
					data:{
						type:navItem.state,
						page:navItem.page,
						limit:this.limit
					},
					dataType: 'json',
					responseType: 'text'
				})
				.then(res => {
					if(res.data.json&&res.data.json.length>0){
						navItem.list = navItem.list.concat(res.data.json);
						navItem.page++;
						navItem.loadingType = res.data.json.length>=this.limit?'loadmore':"nomore";
					}else {
						navItem.loadingType = 'nomore';
					}
					navItem.loaded = true;
				})
			},
			showNote(target){
				if(target.status==3){
					this.content = target.note;
					this.show = true;
				}
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #fafafa;
	}
	.nav{
		background-color: #FFFFFF;
		position: fixed;
		top: var(--window-top);
		z-index: 99;
		width: 100%;
	}
	.swiper-box{
		padding: 0 20rpx;
		padding-top: 70rpx;
		margin-bottom: 30rpx;
		height: 100%;
	}
	.item{
		background-color: #FFFFFF;
		padding: 30rpx;
		margin-top: 30rpx;
		border-radius: 14rpx;
		.title{
			font-size: 28rpx;
		}
		.time{
			margin-top: 20rpx;
			font-size: 26rpx;
			color: #747272;
		}
		.number{
			color: #ffad2d;
			font-size: 28rpx;
		}
	}
	.flex-left{
		flex: 1;
	}
	.cz-list{
		
		.item{
			padding: 20rpx;
			background-color: #FFFFFF;
			border-radius: 14rpx;
			margin-top: 30rpx;
		}
		.number{
			flex: 1;
			color: #333333;
		}
		.status{
			flex: 1;
			color: #9e3939;
		}
		.time{
			color: #999797;
		}
	}
	.mark{
		font-size: 26rpx;
		margin-top: 30rpx;
		color: #7c7777;
	}
</style>
